package com.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.google.common.collect.Maps;
import com.order.feign.client.GoodsService;
import com.order.pojo.Order;
import com.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: OrderController
 * @Description: 控制层
 * @author: JiaZhenpeng
 * @data: 2022/11/1312:40
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;


    @SentinelResource("hot")
    @GetMapping("/{orderId}")
    public Map<String, Object> queryOrderByUserId(@PathVariable("orderId") Long orderId) {
        log.info("queryOrderByUserId");
        // 根据id查询订单并返回
        HashMap<String, Object> result = Maps.newHashMap();
        result.put("goodsQuery",this.goodsService.getGoods(orderId));
        result.put("orderQuery", this.orderService.queryOrderById(orderId));
        return result;
    }

    @GetMapping("/query")
    public String queryOrder() {
        log.info("query order");
        this.orderService.queryGoods();
        return "查询订单成功";
    }

    @GetMapping("/save")
    public String saveOrder() {
        log.info("save order");
        this.orderService.queryGoods();
        return "保存订单成功";
    }

    @GetMapping("/update")
    public String updateOrder() {
        log.info("update order");
        return "更新订单成功";
    }
}
